package priv.conceit.study.leetcode.simple.official;

import java.util.HashSet;
import java.util.Set;

/**
 * 编号217
 * 存在重复元素
 * <a href="https://leetcode-cn.com/problems/contains-duplicate/">
 *
 *
 * 示例:
 * 输入: [1,2,3,1]
 * 输出:true
 * 示例:
 * 输入: [1,2,3,4]
 * 输出: false
 *
 * @author Conceit
 * @since 1.0.0, 2019/11/07
 */
public class ContainsDuplicate {

	public static void main(String[] args) {
		ContainsDuplicate containsDuplicate=new ContainsDuplicate();
		containsDuplicate.containsDuplicate(new int[]{0,1,2,3,1});
	}

	public boolean containsDuplicate(int[] nums) {
		Set<Integer> set=new HashSet<>();
		for (int i:nums){
			if (set.contains(i)){
				return true;
			}
			set.add(i);
		}
		return false;
	}
}
